package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ShoppingCartMapper {
    //添加购物车
    @Insert("INSERT INTO shopping_cart VALUES (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    public void save(ShoppingCart shoppingCart);

    //更新购物项
    @Update("UPDATE shopping_cart SET number=#{number} WHERE id=#{id}")
    public void update(ShoppingCart shoppingCartOne);

    public ShoppingCart findUserIdAndDishIdOrSetmealId(ShoppingCart shoppingCart);

    /**
     * 作用: 查看购物车
     *
     * @param userId 用户Id
     */
    @Select("SELECT * FROM shopping_cart WHERE user_id=#{userId}")
    List<ShoppingCart> findShoppingCartByUserId(Long userId);

    /**
     * 作用: 删除购物车
     *
     * @return
     */
    @Delete("DELETE FROM shopping_cart WHERE user_id=#{userId}")
    void clean(Long userId);

    @Update("UPDATE shopping_cart SET number=#{number} WHERE id=#{id}")
    void sub(ShoppingCart shoppingCartOne);

    @Delete("DELETE FROM  shopping_cart WHERE dish_id=#{dishId}")
    void deletdish(ShoppingCart shoppingCart);

}
